package com.hsc.account;

import java.util.List;
import java.util.Map;

import com.hsc.db.tools.AccountList;
import com.hsc.db.tools.ItemService;

import android.app.AlertDialog;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListViewAdapter extends BaseAdapter {

	private Context context; // 运行上下文
	private List<AccountList> listItems; // 商品信息集合
	private LayoutInflater listContainer; // 视图容器
	private ItemService items;
	private static String start="NULL";


	public List<AccountList> getListItems() {
		return listItems;
	}

	public void setListItems(List<AccountList> listItems) {
		this.listItems = listItems;
	}

	public ListViewAdapter(Context context, List<AccountList> listItems,ItemService items) {
		this.context = context;
		listContainer = LayoutInflater.from(context); // 创建视图容器并设置上下文
		this.listItems = listItems;
		this.items = items;

		if(items.getlDataFlag("1")!=null)
		{
			start = items.getlDataFlag("1").getType();
		}

	}

	public int getCount() {
		// TODO Auto-generated method stub
		return listItems.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return this.listItems.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * ListView Item设置
	 */
	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		view = listContainer.inflate(R.layout.item, null);
		// 获取控件对象
		TextView date = (TextView) view
				.findViewById(R.id.date);
		TextView id = (TextView) view
				.findViewById(R.id.id);
		TextView amt = (TextView) view
				.findViewById(R.id.amt);
		TextView remark = (TextView) view
				.findViewById(R.id.remark);
		TextView balance = (TextView) view
				.findViewById(R.id.balance);
		TextView zonge = (TextView) view
				.findViewById(R.id.zonge);
		TextView renj = (TextView) view
				.findViewById(R.id.renj);


		if(listItems.size()>0)
		{
			AccountList  obj = listItems.get(position);

			id.setText(String.valueOf(obj.getId()));
			remark.setText(obj.getType());
			amt.setText(String.valueOf(obj.getAmt()));
			balance.setText(String.valueOf(obj.getBalance()));
			date.setText(obj.getDate());

			if(obj.getUse()!=null)
			{
				if(!obj.getUse().equals("null"))
				{
					zonge.setText(obj.getUse());
				}else
				{
					zonge.setText("总金额");
				}

			}

			if(obj.getRemark().startsWith(start))
			{
				renj.setTextColor(Color.parseColor("#99cc33"));
				zonge.setTextColor(Color.parseColor("#99cc33"));
				id.setTextColor(Color.parseColor("#99cc33"));
				remark.setTextColor(Color.parseColor("#99cc33"));
				amt.setTextColor(Color.parseColor("#99cc33"));
				balance.setTextColor(Color.parseColor("#99cc33"));
				date.setTextColor(Color.parseColor("#99cc33"));

			}

		}

		return view;
	}
}
